import * as actionType from "./content";
import * as entireFetchModule from "@/services/modules/enitre";
export const changePageListAction = (pageList) => {
  return {
    type: actionType.CHANGE_PAGELIST,
    pageList,
  };
};

export const changeCurrentPageAction = (currentPage) => {
  return {
    type: actionType.CHANGE_CURRENTPAGE,
    currentPage,
  };
};

export const changeTotalCountAction = (totalCount) => {
  return {
    type: actionType.CHANGE_TOTALCOUNT,
    totalCount,
  };
};

export const changeIsLoadingAction = (isLoading) => {
  return {
    type: actionType.CHANGE_ISLOADING,
    isLoading,
  };
};

export const fetchEntireRoomListAction = (page = 0) => {
  return async (dispatch, getState) => {
    // const offset = (getState().entire.currentPage + 1) * 20;
    const offset = (page + 1) * 20;
    dispatch(changeIsLoadingAction(true));
    const res = await entireFetchModule.fetchEntireRoomList(offset);
    dispatch(changeIsLoadingAction(false));
    dispatch(changePageListAction(res.list));
    dispatch(changeTotalCountAction(res.totalCount));
  };
};
